using System;
using SpecificationPatternCode.Contracts;

namespace SpecificationPatternCode.BaseSpecs
{
	public abstract class AndSpecification <T> : ISpecification<T> where T : IComparable<T>
	{
		private readonly ISpecification<T> _x;
		private readonly ISpecification<T> _y;

		protected AndSpecification(ISpecification<T> x, ISpecification<T> y)
		{
			_x = x;
			_y = y;
		}

		public bool IsSatisfiedBy(T candidate)
		{
			return _x.IsSatisfiedBy(candidate) && _y.IsSatisfiedBy(candidate);
		}
	}
}